//
//  AppDelegate.m
//  Test3
//
//  Created by 王冲 on 2019/1/31.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "ViewController2.h"
#import "ViewController3.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[ViewController new]];
    [self.window makeKeyAndVisible];
    return YES;
}


// 已经过期,不建议使用(建议把这2个方法同时实现)
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{

    [self dealopenURL:url];
    return YES;
}

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
    
    [self dealopenURL:url];
    
    return YES;
}

-(void)dealopenURL:(NSURL *)url{

    NSLog(@"协议=%@ IP或者是域名=%@ 路径=%@ 参数=%@",url.scheme,url.host,url.path,url.query);
    
    // 1.获取主控制器
    UINavigationController *rootNav = (UINavigationController *)self.window.rootViewController;
    ViewController *mainVc = [rootNav.childViewControllers firstObject];
    [rootNav popToRootViewControllerAnimated:NO];
    
    if ([url.path isEqualToString:@"/vc2"]) {

        ViewController2 *vc2 = [ViewController2 new];
        vc2.urlString = url.host;
        [mainVc.navigationController pushViewController:vc2 animated:YES];
    } else if ([url.path isEqualToString:@"/vc3"]) {
        
        ViewController3 *vc3 = [ViewController3 new];
        vc3.urlString = url.host;
        [mainVc.navigationController pushViewController:vc3 animated:YES];
    }
    
}

@end
